package org.jeecg.modules.product.risk.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.product.risk.entity.TbBaseMeasuresTask;
import org.jeecg.modules.product.risk.mapper.TbBaseMeasuresTaskMapper;
import org.jeecg.modules.product.risk.service.ITbBaseMeasuresTaskService;
import org.jeecg.modules.product.risk.thread.TaskDerivationThread;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description: 隐患排查任务信息
 * @Author: jeecg-boot
 * @Date:   2024-03-02
 * @Version: V1.0
 */

@Slf4j
@Service
public class TbBaseMeasuresTaskServiceImpl extends ServiceImpl<TbBaseMeasuresTaskMapper, TbBaseMeasuresTask> implements ITbBaseMeasuresTaskService, Job {
	
	@Autowired
	private TbBaseMeasuresTaskMapper tbBaseMeasuresTaskMapper;
	@Override
	public List<TbBaseMeasuresTask> selectByMainId(String mainId) {
		return tbBaseMeasuresTaskMapper.selectByMainId(mainId);
	}

	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
		log.info("--------开始衍生风险排查任务数据------------");
		/*创建一个有固定个数的线程池*/
		//ExecutorService executor = Executors.newFixedThreadPool(5);
		/*创建一个动态变化的线程池*/
		ExecutorService executor = Executors.newCachedThreadPool();
		Runnable task = new TaskDerivationThread();
		executor.execute(task);//提交任务到线程池
		log.info("--------结束衍生风险排查任务数据------------");
	}
}
